// ================================================================================
// 		File: PartyRepresentativeStudio.cs
// 		Desc: 
//  
// 		Called by:   
//               
// 		Auth: chenwenzhi（）
// 		Date: 2016-03-23 01:45
// ================================================================================
// 		Change History
// ================================================================================
// 		Date:		Author:				Description:
// 		--------	--------			-------------------
//    
// ================================================================================
// 
// ================================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq; 
using System.Text;
using MySql.Data.MySqlClient;
using ZHDJ.Core;

namespace ZHDJ.Data.Models.Center
{
    /// <summary>
    /// 党代表工作室
    /// </summary>   
    public class PartyRepresentativeStudio : EntityBase
    { 
		#region 属性
		
        /// <summary>
        /// 工作室名称
        /// </summary>
        public string StudioName { get; set; }
		
        /// <summary>
        /// 工作室图片ID
        /// </summary>
        public string ImageID { get; set; }
		
        /// <summary>
        /// 工作室电话
        /// </summary>
        public string StudioPhone { get; set; }
		
        /// <summary>
        /// 联络员
        /// </summary>
        public string LinkMan { get; set; }
		
        /// <summary>
        /// 联络员手机号
        /// </summary>
        public string LinkPhone { get; set; }
		
        /// <summary>
        /// 工作室简介
        /// </summary>
        public string Summary { get; set; }

        /// <summary>
        /// 工作室类型（1组织、2个人）
        /// </summary>
        public string Category { get; set; }
		
        /// <summary>
        /// 工作室所属（个人、组织）ID
        /// </summary>
        public string ObjectID { get; set; }
		
        /// <summary>
        /// 排序
        /// </summary>
        public int OrderNo { get; set; }
				
        /// <summary>
        /// 状态（1草稿，4发布）
        /// </summary>
        public int Status { get; set; }
        /// <summary>
        /// 创建用户
        /// </summary>
        public string CreateBy { get; set; }
		
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }
		
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? ModifyTime { get; set; }
		
        /// <summary>
        /// 修改用户
        /// </summary>
        public string ModifyBy { get; set; }
		
		#endregion 

		#region 查询管理

		 public static DataSet GetGridData(int pageIndex, int pageSize,string category,string status, string searchKey = "")
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize}
            };


            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS  data.ID,data.StudioName,data.ImageID,data.StudioPhone,
                        data.LinkMan,data.LinkPhone,data.Summary,data.Category,data.ObjectID,
                        data.OrderNo,data.CreateBy,data.CreateTime,data.ModifyTime,data.ModifyBy,
                        case data.Category when 2 then '个人' else '组织' end as CategoryName,
                        case data.Status when 4 then '已发布' else '草稿' end as  StatusName,
                        case data.Category when 2 then
(select UserName from tblpartyorgmember where tblpartyorgmember.LoginID=data.ObjectID limit 1)
else (select BranchName from tblpartyorgBranch where tblpartyorgBranch.BranchID=data.ObjectID limit 1) end as ObjectName
                        from tblPartyRepresentativeStudio data
                        where 1=1 ");
            if (!string.IsNullOrEmpty(searchKey))
            {
                sb.Append(" and data.StudioName like ?key ");
                parameters.Add(
                    new MySqlParameter() { DbType = DbType.String, ParameterName = "key", Value = string.Format("%{0}%", searchKey) });
            }
            if (!string.IsNullOrEmpty(category))
            {
                sb.Append(" and data.category=?category");
                parameters.Add(new MySqlParameter() { DbType = DbType.String, ParameterName = "category", Value = category });
            }
            if (!string.IsNullOrEmpty(status))
            {
                sb.Append(" and data.status=?status");
                parameters.Add(new MySqlParameter() { DbType = DbType.Int32, ParameterName = "status", Value = status });
            }
            sb.Append(" order by status desc,data.Category, data.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
		#endregion
    }
}
